/**
 * 
 */
package com.qdairlines.service.mq.send.impl;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;
import org.springframework.stereotype.Service;

import com.qdairlines.service.mq.send.SendQService;

/**
 * @author pangyannan
 * @date 2017年6月6日
 * @company QingDao Airlines
 * @description
 */
@Service
public class SendQServiceimpl implements SendQService{
	private static final Logger logger = LoggerFactory.getLogger(SendQServiceimpl.class);

	@Autowired
	private JmsTemplate jmsTemplateSendQ; //sendQ 是在applicationContext-mq.xml 中定义的发送队列名称、
	
	@Autowired
	private JmsTemplate jmsTemplatesendQWx;//微信消息发送队列
	
	@Override
	public void sendMsg(final String msg){
		logger.info("接收消息>>>>" + msg);
		this.jmsTemplateSendQ.send( this.getMessageCreator(msg));
		logger.info("发送MQ完成>>>>" + msg);

	}

	@Override
	public void sendMsgWx(String msg) {
		logger.info("接收消息>>>>" + msg);
		this.jmsTemplatesendQWx.send(this.getMessageCreator(msg));
		logger.info("发送MQ完成>>>>" + msg);
	}
	
	/**
	 * 构造消息体
	 * @param msg
	 * @return
	 */
	private MessageCreator getMessageCreator(final String msg){
		MessageCreator messageCreator = new MessageCreator(){
			 @Override  
		      public Message createMessage(Session session) throws JMSException{
		          return session.createTextMessage(msg);
			  }
		};
		
		return messageCreator;
	}

}
